Add a --version argument that also outputs features
authorColin Walters <walters@verbum.org>
Wed, 1 May 2013 23:15:06 +0000 (19:15 -0400)
committerColin Walters <walters@verbum.org>
Wed, 1 May 2013 23:15:06 +0000 (19:15 -0400)
And use it in the tests to skip libarchive tests when the build
doesn't support it.

Makefile.am
configure.ac
src/ostree/ot-main.c
tests/t0006-libarchive.sh

index e3ce06cfd71b0f795c7e9626713d1b95ceb23afb..0ad12e473ee9eb862efcefbe9a90e650d61a56ec 100644 (file)
@@ -17,6 +17,7 @@
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 AM_CPPFLAGS = -DDATADIR='"$(datadir)"' -DLIBEXECDIR='"$(libexecdir)"' \
+       -DOSTREE_FEATURES='"$(OSTREE_FEATURES)"' \
        -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_34 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_34 \
        -DSOUP_VERSION_MIN_REQUIRED=SOUP_VERSION_2_40 -DSOUP_VERSION_MAX_ALLOWED=SOUP_VERSION_40
 AM_CFLAGS = $(WARN_CFLAGS)
index d95f5d8e4f8622153e535cafb867dac14e04a598..8acf7dac69bbc3314dac3821bf8b60a21efdeb9a 100644 (file)
@@ -28,6 +28,9 @@ AC_SUBST(WARN_CFLAGS)
 LT_PREREQ([2.2.4])
 LT_INIT([disable-static])
 
+OSTREE_FEATURES=""
+AC_SUBST([OSTREE_FEATURES])
+
 AC_ARG_ENABLE(triggers-only,
            AS_HELP_STRING([--enable-triggers-only], [Only build and install triggers]),,
            enable_triggers_only=no)
@@ -70,12 +73,14 @@ AS_IF([test x$enable_embedded_dependencies = xyes], [
     ])
     AS_IF([test x$have_soup = xyes], [
        PKG_CHECK_MODULES(OT_DEP_SOUP, $SOUP_DEPENDENCY)
+        AC_DEFINE(HAVE_LIBSOUP, 1, [Define if we have libsoup.pc])
        with_soup=yes
     ], [
        with_soup=no
     ])
   ], [ with_soup=no ])
 ])
+if test x$with_soup != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libsoup"; fi
 AM_CONDITIONAL(USE_LIBSOUP, test x$with_soup != xno)
 
 LIBARCHIVE_DEPENDENCY="libarchive >= 2.8.0"
@@ -117,6 +122,7 @@ AS_IF([ test x$with_libarchive != xno ], [
        with_libarchive=no
     ])
 ], [ with_libarchive=no ])
+if test x$with_libarchive != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libarchive"; fi
 AM_CONDITIONAL(USE_LIBARCHIVE, test $with_libarchive != no)
 
 AS_IF([test x$cross_compiling != xyes && test -d /etc/kernel && test x$enable_triggers_only != xyes ],
index 7e9699e9e97cf0d949235ec72526623b8b937944..43fda01ce057563d066786d49b1ff654239950cf 100644 (file)
 #include "ot-main.h"
 #include "otutil.h"
 
+static gboolean opt_version;
+
+static GOptionEntry main_options[] = {
+  { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Display version", NULL },
+  { NULL }
+};
+
 int
 ostree_usage (char **argv,
               OstreeCommand *commands,
@@ -80,6 +87,7 @@ ostree_run (int    argc,
             OstreeCommand *commands,
             GError **res_error)
 {
+  GOptionContext *optcontext;
   OstreeCommand *command;
   GError *error = NULL;
   int cmd_argc;
@@ -104,6 +112,19 @@ ostree_run (int    argc,
   if (argc < 2)
     return ostree_usage (argv, commands, TRUE);
 
+  optcontext = g_option_context_new ("COMMAND [OPTIONS...]");
+  g_option_context_add_main_entries (optcontext, main_options, NULL);
+  g_option_context_set_ignore_unknown_options (optcontext, TRUE);
+
+  if (!g_option_context_parse (optcontext, &argc, &argv, &error))
+    goto out;
+
+  if (opt_version)
+    {
+      g_print ("%s\n  %s\n", PACKAGE_STRING, OSTREE_FEATURES);
+      return 0;
+    }
+
   have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
 
   if (have_repo_arg)
index 4936389cee373150244ee7d51df28bd69fd61216..38c9affb7a2598d2b39df2f428e030010096c27e 100755 (executable)
 
 set -e
 
+if ! ostree --version | grep -q -e '\+libarchive'; then
+    exit 77
+fi
+
 echo "1..7"
 
 . $(dirname $0)/libtest.sh